package com.jetgege.smartbox.BoxSetting;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jetgege.smartbox.Base.BaseActivity;
import com.jetgege.smartbox.MainActivity;
import com.jetgege.smartbox.R;
import com.kaopiz.kprogresshud.KProgressHUD;

import butterknife.BindView;
import butterknife.OnClick;

public class InputFingerprintActivity extends BaseActivity {

    @BindView(R.id.input_fingerprint_toolbar)
    Toolbar inputFingerprintToolbar;
    String action = null;
    @BindView(R.id.bt_Pass)
    Button btPass;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_input_fingerprint;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initValue();
    }

    private void initValue() {
        action = getIntent().getAction();
        inputFingerprintToolbar.setTitle("指纹录入");
        setSupportActionBar(inputFingerprintToolbar);
        if (!action.equals("FirstUserActivity")) {
            inputFingerprintToolbar.setNavigationIcon(R.drawable.bar_back_btn);
            btPass.setVisibility(View.GONE);
        }
        else btPass.setVisibility(View.VISIBLE);
        inputFingerprintToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.authentication, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        addSucc();
        return true;
    }

    private void addSucc() {
        TextView tv_Tip = new TextView(this);
        tv_Tip.setText("录入成功！");
        tv_Tip.setTextColor(Color.WHITE);
        tv_Tip.setTextSize(18);
        final KProgressHUD hudUNUse = KProgressHUD.create(this)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setCustomView(tv_Tip)
                .setCancellable(true)
                .setAutoDismiss(true)
                .show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hudUNUse.dismiss();
                if (action.equals("FirstUserActivity"))
                    startActivity(new Intent(InputFingerprintActivity.this, MainActivity.class));
                else
                    startActivity(new Intent(InputFingerprintActivity.this, CompleteTipsActivity.class));
                overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
                finish();
            }
        }, 1000);
    }

    /**
     * 跳过指纹录入
     * 可在设置中录入
     */
    @OnClick(R.id.bt_Pass)
    public void onViewClicked() {

        startActivity(new Intent(InputFingerprintActivity.this, MainActivity.class));
        overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
        finish();
    }
}
